
<?php include('./classes/mailer.php'); ?>
<?php include('./classes/employee.php'); ?>
<?php 
require_once('KLogger.php');   
$log = new KLogger ( "./logs/forgotPassword.txt" , KLogger::DEBUG );
?>


<?php
//Retaining Variables
$user_name = $_REQUEST['user_name'];

if($user_name==null || $user_name== ""|| $user_name == "")
{
	header('Location: http://172.26.195.159/checklist/php/index.php');
}
?>


<?php

//creating a connection.
$con = mysql_connect("localhost","root","");
mysql_select_db("checklist", $con);

$check = "select * from employees where username = '$user_name'";
$result = mysql_query($check);

//Check if password is ok
if(mysql_num_rows($result))
{
$data = mysql_fetch_assoc($result);
$email = $data['email'];
$password = $data['password'];

//Send mail now....

 /*********************************Send Mail***************************************************/

$m = new mailer();

//Setting to and ccs'
$m->set_to($email);

//Setting message and body..
$m->set_headers('From: "WebChecklist Notification" <WebChecklist_Message_Broker@tcs.com>'."\r\n"."");

$m->set_subject("WebChecklist Password for username : ".$user_name);
$m->set_body("Hi , "."\n\n"."Please use following credentials to log onto WebChecklist."."\n\n"."Username :".$user_name."\n"."Password :".$password."\n\n"."Thanks."."\n\n"."Regards ,"."\n"."iVSE - WebChecklist Messenger"
."\n\n"."In case of concerns :"."\n"."mailto:gaurav.pruthi@tcs.com"."\n"."ESN : 3048");

$m->sendmail();	
//*******************************End Mail Part**********************************************

$log->logInfo('Accessed by  :'.$user_name);
echo '<script type="text/javascript">','alert("Your password has been sent to your mail ID !!!");',
'window.location = "http://172.26.195.159/checklist/php/index.php";' ,'</script>';
}

else
{
echo '<script type="text/javascript">','alert("Sorry Wrong username entered , please try again");',
'window.location = "http://172.26.195.159/checklist/php/forgotPassword.php";' ,'</script>';
}
?>